package com.example.service.impl;

import com.example.mapper.calibrationRecordMapp;
import com.example.pojo.calibrationRecordPojo;
import com.example.service.calibrationRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;

@Service
public class calibrationRecordImpl implements calibrationRecordService {
    @Autowired
    private calibrationRecordMapp calibrationRecordMapp;
    //对一个字段，从老值更改为新值
    public void editByField(String fieldName, String old, String newData) {
        calibrationRecordMapp.editByField(fieldName,old,newData);
    }
    //从基础信息表中拿到所有数据后，拿到一行插入一行校准记录数据
    public void insertOneRow(calibrationRecordPojo pojo){
        //生成一段低代码格式的id
        UUID uuid = UUID.randomUUID();
        String uuidStr = uuid.toString().replace("-", "");
        pojo.setId(uuidStr);
        pojo.setEstablishTime(LocalDateTime.now());
        pojo.setUpdate_time(LocalDateTime.now());
        pojo.setSys_deleted(0);
        calibrationRecordMapp.insertOneRow(pojo);
    }
    //查询所有校准记录数据
    public List<calibrationRecordPojo> queryAll(){
        List<calibrationRecordPojo> list = calibrationRecordMapp.queryAll();
        return list;
    }
    //根据id编辑某一行校准记录数据，都是字符串类型
    public void editOneById(calibrationRecordPojo pojo){
        //定义修改时间生成规则
        pojo.setUpdateTime(LocalDateTime.now());
        //调用 Mapper 编辑数据
        calibrationRecordMapp.editOneById(pojo);
    }

    //根据编号，修改删除标记位
    public void editByFieldInt(String fieldName, String fieldVal, int deleteVal) {
        System.out.println(fieldVal);
        calibrationRecordMapp.editByFieldInt(fieldName, fieldVal, deleteVal);
    }
}
